﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SnailGame.Utility.DataAccess;
using System.Configuration;
using System.Collections;
using Com.Crc.PoJo.Model.Resource;

namespace Com.Crc.ResManage.DAL.EquipManage
{
    public class BroadBandManagerSubstationDAL
    {
        DataBroker broker = new DataBroker();
        /// <summary>
        /// 删除设备，修改状态位为0
        /// </summary>
        /// <param name="wlanList"></param>
        /// <returns></returns>
        public bool DeleteSubstationData(ArrayList substationList)
        {
            string id = "";
            for (int i = 0; i < substationList.Count; i++)
            {
                id += substationList[i] + ",";
            }
            id = id.Substring(0, id.Length - 1);
            string strSql = @"UPDATE TT_RESOURCE_SUBSTATION SET S_STATE='0' WHERE N_ID IN (" + id + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 修改交换设备信息
        /// </summary>
        /// <param name="data">model实体</param>
        /// <returns></returns>
        public bool UpdateSubstationData(Substation data)
        {
            string strSql = @" UPDATE TT_RESOURCE_SUBSTATION
                                  SET" +
                                    "S_NO='" + data.S_NO + @"',
                                    S_NAME='" + data.S_NAME + @"',
                                    N_LEVEL=" + data.N_LEVEL + @",
                                    N_PARENT_ID=" + data.N_PARENT_ID + @",
                                    S_ADDRESS='" + data.S_ADDRESS + @"',
                                    S_HOURSE_TYPE='" + data.S_HOURSE_TYPE + @"',
                                    S_HOURSE_MONEY='" + data.S_HOURSE_MONEY + @"',
                                    S_HOURSE_TIME='" + data.S_HOURSE_TIME + @"',
                                    N_PARENT_SUBSTATION_ID=" + data.N_PARENT_SUBSTATION_ID + @",
                                    D_START=" + data.D_START.ToString("yyyy-MM-dd HH:mm:ss") + @",
                                    S_KONGTIAO='" + data.S_KONGTIAO + @"',
                                    S_KONGTIAO_BAK='" + data.S_KONGTIAO_BAK + @"',
                                    N_M_TRANSPORT_ID=" + data.N_M_TRANSPORT_ID + @",
                                    N_M_EXCHANGE_ID=" + data.N_M_EXCHANGE_ID + @",
                                    N_M_WLAN_ID=" + data.N_M_WLAN_ID + @",
                                    N_UP_CHANNEL_ID=" + data.N_UP_CHANNEL_ID + @",
                                    N_2M=" + data.N_2M + @",
                                    N_M_POWER_ID=" + data.N_M_POWER_ID + @",
                                    N_M_POWER_TYPE_ID=" + data.N_M_POWER_TYPE_ID + @",
                                    N_PON_OLT_ID=" + data.N_PON_OLT_ID + @",
                                    N_CYCLE_MONITER_ID=" + data.N_CYCLE_MONITER_ID + @",
                                    S_ROTATION_IP='" + data.S_ROTATION_IP + @"',
                                    S_OLT_IP='" + data.S_OLT_IP + @"',
                                    N_INTEGRAL_ID=" + data.N_INTEGRAL_ID + @",
                                    S_INTEGRAL_BAK='" + data.S_INTEGRAL_BAK + @"',
                                    N_ODF_ID=" + data.N_ODF_ID + @",
                                    S_ODF_BAK='" + data.S_ODF_BAK + @"',
                                    O_M_OTHER=" + data.O_M_OTHER + @",
                                    S_BAK='" + data.S_BAK + @"',
                                    S_STATE='" + data.S_STATE + @"',
                                    D_CRATE=" + data.D_CRATE.ToString("yyyy-MM-dd HH:mm:ss") + @",
                                    D_MODIFY=" + data.D_MODIFY.ToString("yyyy-MM-dd HH:mm:ss") + @",
                                    WHERE N_ID=" + data.N_ID;
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

        /// <summary>
        /// 新增交换设备信息
        /// </summary>
        /// <param name="strBranchID">分局ID</param>
        /// <param name="strOfficeID">局点ID</param>
        /// <param name="strEquipID">设备ID</param>
        /// <returns></returns>
        public bool AddSubstationData(Substation data)
        {
            string strSql = @" INSERT INTO TT_RESOURCE_SUBSTATION(S_NO,S_NAME,N_LEVEL,N_PARENT_ID,S_ADDRESS,S_HOURSE_TYPE,S_HOURSE_MONEY,S_HOURSE_TIME,N_PARENT_SUBSTATION_ID,D_START,S_KONGTIAO,S_KONGTIAO_BAK,N_M_TRANSPORT_ID,N_M_EXCHANGE_ID,N_M_WLAN_ID,N_UP_CHANNEL_ID,N_2M,N_M_POWER_ID,N_M_POWER_TYPE_ID,N_PON_OLT_ID,N_CYCLE_MONITER_ID,S_ROTATION_IP,S_OLT_IP,N_INTEGRAL_ID,S_INTEGRAL_BAK,N_ODF_ID,S_ODF_BAK,O_M_OTHER,S_BAK,S_STATE,D_CRATE,D_MODIFY)
                                    VALUES (" +
                                                "'" + data.S_NO + "'" + "," +
                                                "'" + data.S_NAME + "'" + "," +
                                                data.N_LEVEL + "," +
                                                data.N_PARENT_ID + "," +
                                                "'" + data.S_ADDRESS + "'" + "," +
                                                "'" + data.S_HOURSE_TYPE + "'" + "," +
                                                "'" + data.S_HOURSE_MONEY + "'" + "," +
                                                "'" + data.S_HOURSE_TIME + "'" + "," +
                                                data.N_PARENT_SUBSTATION_ID + "," +
                                                "'" + data.D_START.ToString("yyyy-MM-dd HH:mm:ss") + "'" +"," +
                                                "'" + data.S_KONGTIAO + "'" + "," +
                                                "'" + data.S_KONGTIAO_BAK + "'" + "," +
                                                data.N_M_TRANSPORT_ID + "," +
                                                data.N_M_EXCHANGE_ID + "," +
                                                data.N_M_WLAN_ID + "," +
                                                data.N_UP_CHANNEL_ID + "," +
                                                data.N_2M + "," +
                                                data.N_M_POWER_ID + "," +
                                                data.N_M_POWER_TYPE_ID + "," +
                                                data.N_PON_OLT_ID + "," +
                                                data.N_CYCLE_MONITER_ID + "," +
                                                "'" + data.S_ROTATION_IP + "'" + "," +
                                                "'" + data.S_OLT_IP + "'" + "," +
                                                data.N_INTEGRAL_ID + "," +
                                                "'" + data.S_INTEGRAL_BAK +"'" +  "," +
                                                data.N_ODF_ID + "," +
                                                "'" + data.S_ODF_BAK + "'" + "," +
                                                data.O_M_OTHER + "," +
                                                "'" + data.S_BAK + "'" + "," +
                                                "'" + data.S_STATE + "'" + "," +
                                                "'" +data.D_CRATE.ToString("yyyy-MM-dd HH:mm:ss") + "'" +"," +
                                                "'" +data.D_MODIFY.ToString("yyyy-MM-dd HH:mm:ss") + "'" + ")";
            return broker.ExecuteForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }
        /// <summary>
        /// 查询交换设备信息
        /// </summary>
        /// <param name="strBranchID">分局ID</param>
        /// <param name="strOfficeID">局点ID</param>
        /// <param name="strEquipID">设备ID</param>
        /// <returns></returns>
        public System.Data.DataTable QuerySubstationData(string strBranchID, string strOfficeID, string strEquipID)
        {
            string strSql = @" SELECT N_ID,S_NO,S_NAME,N_LEVEL,N_PARENT_ID,S_ADDRESS,S_HOURSE_TYPE,S_HOURSE_MONEY,S_HOURSE_TIME,N_PARENT_SUBSTATION_ID,D_START,S_KONGTIAO,S_KONGTIAO_BAK,N_M_TRANSPORT_ID,N_M_EXCHANGE_ID,N_M_WLAN_ID,N_UP_CHANNEL_ID,N_2M,N_M_POWER_ID,N_M_POWER_TYPE_ID,N_PON_OLT_ID,N_CYCLE_MONITER_ID,S_ROTATION_IP,S_OLT_IP,N_INTEGRAL_ID,S_INTEGRAL_BAK,N_ODF_ID,S_ODF_BAK,O_M_OTHER,S_BAK,S_STATE,D_CRATE,D_MODIFY FROM TT_RESOURCE_SUBSTATION WHERE S_STATE='1' ";
            
            return broker.ExecuteQueryForOleDB(strSql, ConfigurationManager.ConnectionStrings["CRCAppConn"].ToString());
        }

    }
}
